﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Olympic_email_to_future.Module;

namespace FutureMeWeb
{
    public partial class modify_information : System.Web.UI.Page
    {
        public Olympic_email_to_future.IBLL.IUserBLL bll = Olympic_email_to_future.BLLFactory.BusinessFactory.CreateUserBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                if (!IsPostBack)
                {
                    UserInfo user = (UserInfo)Session["User"];
                    AccountBtn.Text = user.userMailAddress;
                    LoginBtn.Visible = false;
                    RegisterBtn.Visible = false;
                    user = bll.getUser(user);
                    TextBox1.Text = user.userName;
                    TextBox2.Text = user.userAddress;
                    TextBox3.Text = user.userPhone;
                    if (user.userSex == 0)
                        DropDownList1.SelectedValue = "1";
                    else
                        DropDownList1.SelectedValue = "0";

                }
            }
            else
            {
                AccountBtn.Visible = false;
                LogoffBtn.Visible = false;
            }

        }

        protected void Button1_Click(object sender, EventArgs e) 
        {
            UserInfo user = new UserInfo();
            UserInfo userinfo = (UserInfo)Session["User"];
            user.userMailAddress = userinfo.userMailAddress;
            user.userName = TextBox1.Text;
            user.userAddress = TextBox2.Text;
            user.userPhone = TextBox3.Text;
            if (DropDownList1.SelectedValue == "0")
                user.userSex = 1;
            else
                user.userSex = 0;
            bll.updateUser(user);
            Response.Write("<script>alert('修改信息成功！')</script>");
        }

        protected void LogoffBtn_Click(object sender, EventArgs e)
        {
            Session.Abandon();
        }

    }
}